import { ViewCtrlBase } from './../../../view/ViewCtrlBase';
/*
 * @Descripttion:滑动节点复用scroll组件子节点父类
 * @Author:jindekun
 * @Date: 2021-11-01 11:09:03
 */

import { _decorator } from "cc";
import BaseComponent from "../../BaseComponent";
import { IListViewItem } from "./IListViewItem";


const { ccclass, property } = _decorator;
@ccclass
export default class ListViewItemBase extends BaseComponent implements IListViewItem {

    /**当前项索引，0表示第一项 */
    public itemIdx: number = 0;
    /**数据 */
    protected data: any;
    /**列表中总数量 */
    protected totalCount: number;
    /**控制器代理 */
    protected vc: ViewCtrlBase;
    /**
     * 刷新
     * @param itemIdx 当前项ID
     * @param data   数据
     */
    public updateItem(itemIdx: number, data: any, totalCount: number) {
        if (!data) {
            return;
        }
        let oldItemIdx = this.itemIdx;
        this.itemIdx = itemIdx;
        this.data = data;
        this.totalCount = totalCount;
        this.node.setSiblingIndex(itemIdx);
        this.dataChanged();
        if (itemIdx !== oldItemIdx) {
            this.itemIdxChanged();
        }
    }

    /**数据改变,子类重写 */
    protected dataChanged() {

    }

    /**数据索引改变,子类重写 */
    protected itemIdxChanged() {

    }

    public setDelegage(vc: ViewCtrlBase) {
        this.vc = vc;
    }


}

